package 动态规划;

public class Algo213打家劫舍II {
    public static void main(String[] args) {

    }

        public int rob(int[] nums) {
            int n = nums.length;
            if(n==1) {
                return nums[0];
            }
            int[] dp = new int[n];

            for (int i = 0; i < nums.length; i++) {
                dp[i] = nums[i];
                if( i - 1 <=0) {
                    continue;
                }

                if(i == nums.length - 1) {
                    for (int j = 1; j < i - 1; j+=2) {
                        dp[i] = Math.max(dp[i], dp[j]+nums[i]);
                    }
                }else {
                    for (int j = 0; j < i-1; j++) {
                        dp[i] = Math.max(dp[i], dp[j]+nums[i]);
                    }
                }

            }
            int result = 0;
            for (int i = 0; i < dp.length; i++) {
                result = Math.max(result, dp[i]);
            }
            return result;
        }
}
